package com.uenpay.oem.widget.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.uenpay.oem.R;

/**
 * Created by PS on 2017/6/20.
 */

public class UenChooseDialog extends Dialog implements View.OnClickListener {
	private final Activity activity;
	private OnCloseClickListener onCloseClickListener;
	private OnCancleListener onCancleListener;
	private OnConfirmListener onConfirmListener;

	private String message;

	private TextView tvMsg;
	private Button btnCancle;
	private Button btnComfirm;
	private ImageView ivClose;

	public UenChooseDialog(Context context, Activity activity) {
		super(context, R.style.dialog_custom);
		this.activity = activity;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_resume);
		Window window = getWindow();
		window.setGravity(Gravity.CENTER); // 此处可以设置dialog显示的位置为居中
		// 按空白处不能取消动画
		setCanceledOnTouchOutside(false);

		WindowManager m = activity.getWindowManager();
		Display d = m.getDefaultDisplay(); // 获取屏幕宽、高度
		WindowManager.LayoutParams p = window.getAttributes(); // 获取对话框当前的参数值
		p.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.65，根据实际情况调整
		window.setAttributes(p);

		initview();

	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	private void initview() {
		tvMsg = (TextView) findViewById(R.id.tv_message);
		btnCancle = (Button) findViewById(R.id.btn_cancle);
		btnComfirm = (Button) findViewById(R.id.btn_comfirm);
		tvMsg.setText(message);
		ivClose = (ImageView) findViewById(R.id.dialog_close_code);
		btnCancle.setOnClickListener(this);
		btnComfirm.setOnClickListener(this);
		ivClose.setOnClickListener(this);
	}

	public OnConfirmListener getOnConfirmListener() {
		return onConfirmListener;
	}

	public void setOnConfirmClickListener(OnConfirmListener onConfirmListener) {
		this.onConfirmListener = onConfirmListener;
	}

	public OnCancleListener getOnCancleListener() {
		return onCancleListener;
	}

	public void setOnCancleClickListener(OnCancleListener onCancleListener) {
		this.onCancleListener = onCancleListener;
	}

	public OnCloseClickListener getOnCloseClickListener() {
		return onCloseClickListener;
	}

	public void setOnCloseClickListener(OnCloseClickListener onCloseClickListener) {
		this.onCloseClickListener = onCloseClickListener;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_cancle:
			if (onCancleListener != null) {
				onCancleListener.onCancle();
			}
			break;
		case R.id.btn_comfirm:
			if (onConfirmListener != null) {
				onConfirmListener.onConfirm();
			}
			break;
		case R.id.dialog_close_code:
			this.dismiss();
			if (onCloseClickListener != null) {
				onCloseClickListener.onClose();
			}
			break;
		}
	}

	public interface OnCancleListener {
		void onCancle();
	}

	public interface OnConfirmListener {
		void onConfirm();
	}

	public interface OnCloseClickListener {
		void onClose();
	}

}
